//
//  XHIntegralRulesViewController.m
//  umibus
//
//  Created by 冷山 on 16/6/16.
//  Copyright © 2016年 lexingsoft. All rights reserved.
//

#import "XHIntegralRulesViewController.h"

#define SCREEN_HEIGHT                   ([UIScreen mainScreen].bounds.size.height)
#define SCREEN_WIDTH                    ([UIScreen mainScreen].bounds.size.width)

@interface XHIntegralRulesViewController ()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *la_bgViewHeight;
@property (weak, nonatomic) IBOutlet UIView *ui_bgView;
@property (weak, nonatomic) IBOutlet UIView *ui_shadowView;
@property (strong, nonatomic) NSTimer *timer;

@end

@implementation XHIntegralRulesViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.ui_bgView.layer.masksToBounds = YES;
    self.ui_bgView.layer.cornerRadius = 8;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self goAnimation];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)onClickAction:(id)sender
{
    [UIView animateWithDuration:0.35 animations:^{
        
        self.la_bgViewHeight.constant = -350;
        [self.view layoutIfNeeded];
    }];
    self.timer = [NSTimer scheduledTimerWithTimeInterval:0.35
                                                  target:self selector:@selector(cancelViewController) userInfo:nil repeats:YES];

}
- (IBAction)cancelAction:(id)sender
{
    [UIView animateWithDuration:0.35 animations:^{
        
        self.la_bgViewHeight.constant = -350;
        [self.view layoutIfNeeded];
    }];
    self.timer = [NSTimer scheduledTimerWithTimeInterval:0.35
                                                  target:self selector:@selector(cancelViewController) userInfo:nil repeats:YES];
}

//阻尼动画
- (void)goAnimation
{
    CGPoint startPoint = CGPointMake((SCREEN_WIDTH-276)/2, -(SCREEN_HEIGHT-190)/2);
    self.ui_shadowView.layer.position=startPoint;
    [UIView animateWithDuration:.8 delay:0 usingSpringWithDamping:.5 initialSpringVelocity:1.0 options:UIViewAnimationOptionCurveLinear animations:^{
        CGPoint startPoint = CGPointMake((SCREEN_WIDTH-276)/2, (SCREEN_HEIGHT-190)/2 +190);
        self.ui_shadowView.layer.position=startPoint;
        self.la_bgViewHeight.constant = (SCREEN_HEIGHT-276)/2;
        
    } completion:^(BOOL finished) {
        
    }];
}

- (void)cancelViewController
{
    [self dismissViewControllerAnimated:NO completion:^{
        
    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
